//
//  WXPAuthQuestionContentView.m
//  MexicoLoan
//
//  Created by wxp on 2025/2/28.
//

#import "WXPAuthQuestionContentView.h"

@implementation WXPAuthQuestionContentView

#pragma mark - lazy
- (UIView *)viewContent{
    if (!_viewContent) {
        _viewContent = [UIView new];
        _viewContent.backgroundColor = COLOR_WHITE;
        _viewContent.width = SCREEN_WIDTH-LEFT_MARDIN*2;
    }
    return _viewContent;
}
// 未还贷款几笔
- (WXPAuthSelectView *)outstandingView{
    if (!_outstandingView) {
        _outstandingView = [WXPAuthSelectView new];
        ModelBtn * model = [ModelBtn new];
        model.title = @"¿Actualmente, cuántos préstamos online tiene?";
        [_outstandingView resetViewWithModel:model];
        WEAKSELF
        _outstandingView.blockSelect = ^{
            // 打点
            [GlobalMethod buryPointWithPageName:KEY_VerifyQuestion featureName:KEY_Loan_Repayment action:KEY_GET_FOCUS type:KEY_select];
            [GlobalMethod hitPointWithPageName:KEY_VerifyQuestion action:KEY_Loan_Repayment_Focus extInfo:nil];
            NSArray * ary = @[@"0",@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"10"];
            NSMutableArray * array = [NSMutableArray new];
            for (int i = 0; i < ary.count; i ++) {
                ModelBtn * model = [ModelBtn new];
                model.title = ary[i];
                model.content = [NSString stringWithFormat:@"%d",[model.title intValue]+1];
                [array addObject:model];
            }
            UIWindow * window = [[[UIApplication sharedApplication] delegate] window];
            [weakSelf.pickerView resetViewWithAry:array withTag:1];
            [window addSubview:weakSelf.pickerView];
        };
    }
    return _outstandingView;
}
// 是否有逾期
- (WXPAuthSelectView *)overdueView
{
    if (_overdueView == nil) {
        _overdueView = [WXPAuthSelectView  new];
        ModelBtn * model = [ModelBtn new];
        model.title = @"¿En el último medio año, tiene registro de pagos atrasados?";
        [_overdueView resetViewWithModel:model];
        WEAKSELF
        _overdueView.blockSelect = ^{
            // 打点
            [GlobalMethod buryPointWithPageName:KEY_VerifyQuestion featureName:KEY_Overdue action:KEY_GET_FOCUS type:KEY_select];
            [GlobalMethod hitPointWithPageName:KEY_VerifyQuestion action:KEY_Overdue_Focus extInfo:nil];
            NSMutableArray * array = [NSMutableArray new];
            [array addObject:^(void){
                ModelBtn * model = [ModelBtn new];
                model.title = @"No";
                model.content = @"1";
                return model;
            }()];
            [array addObject:^(void){
                ModelBtn * model = [ModelBtn new];
                model.title = @"Sí";
                model.content = @"2";
                return model;
            }()];
            UIWindow * window = [[[UIApplication sharedApplication] delegate] window];
            [weakSelf.pickerView resetViewWithAry:array withTag:2];
            [window addSubview:weakSelf.pickerView];
        };
    }
    return  _overdueView;
}

// 逾期总额
- (WXPAuthSelectView *)totalOverdraftView
{
    if (_totalOverdraftView == nil) {
        _totalOverdraftView = [WXPAuthSelectView  new];
        ModelBtn * model = [ModelBtn new];
        model.title = @"¿Actualmente, cuál es el monto total de los préstamos online?";
        [_totalOverdraftView resetViewWithModel:model];
        WEAKSELF
        _totalOverdraftView.blockSelect = ^{
            // 打点
            [GlobalMethod buryPointWithPageName:KEY_VerifyQuestion featureName:KEY_Overdue_Total action:KEY_GET_FOCUS type:KEY_select];
            [GlobalMethod hitPointWithPageName:KEY_VerifyQuestion action:KEY_Loan_Total_Focus extInfo:nil];
            NSMutableArray * array = [NSMutableArray new];
            [array addObject:^(void){
                ModelBtn * model = [ModelBtn new];
                model.title = @"$0 ~ $500";
                model.content = @"1";
                return model;
            }()];
            [array addObject:^(void){
                ModelBtn * model = [ModelBtn new];
                model.title = @"$500 ~ $1000";
                model.content = @"2";
                return model;
            }()];
            [array addObject:^(void){
                ModelBtn * model = [ModelBtn new];
                model.title = @"$1000 ~ $3000";
                model.content = @"3";
                return model;
            }()];
            [array addObject:^(void){
                ModelBtn * model = [ModelBtn new];
                model.title = @"$3000 ~";
                model.content = @"4";
                return model;
            }()];
            UIWindow * window = [[[UIApplication sharedApplication] delegate] window];
            [weakSelf.pickerView resetViewWithAry:array withTag:3];
            [window addSubview:weakSelf.pickerView];
        };
    }
    return  _totalOverdraftView;
}

// 过期天数
- (WXPAuthSelectView *)overdueDaysView
{
    if (_overdueDaysView == nil) {
        _overdueDaysView = [WXPAuthSelectView  new];
        ModelBtn * model = [ModelBtn new];
        model.title = @"¿Cuál fue el máximo día de pago atrasado?";
        [_overdueDaysView resetViewWithModel:model];
        WEAKSELF
        _overdueDaysView.blockSelect = ^{
            // 打点
            [GlobalMethod buryPointWithPageName:KEY_VerifyQuestion featureName:KEY_Overdue_Days action:KEY_GET_FOCUS type:KEY_select];
            [GlobalMethod hitPointWithPageName:KEY_VerifyQuestion action:KEY_Overdue_Days_Focus extInfo:nil];
            NSMutableArray * array = [NSMutableArray new];
            for (int i = 0; i <= 30; i ++) {
                ModelBtn * model = [ModelBtn new];
                model.title = [NSString stringWithFormat:@"%d días",i];
                model.content = [NSString stringWithFormat:@"%d",[model.title intValue]+1];
                [array addObject:model];
            }
            UIWindow * window = [[[UIApplication sharedApplication] delegate] window];
            [weakSelf.pickerView resetViewWithAry:array withTag:4];
            [window addSubview:weakSelf.pickerView];
        };
    }
    return  _overdueDaysView;
}

// 历史贷款笔数
- (WXPAuthSelectView *)loanNumberView
{
    if (_loanNumberView == nil) {
        _loanNumberView = [WXPAuthSelectView  new];
        ModelBtn * model = [ModelBtn new];
        model.title = @"¿En total, cuántas veces ha solicitado préstamos?";
        [_loanNumberView resetViewWithModel:model];
        WEAKSELF
        _loanNumberView.blockSelect = ^{
            // 打点
            [GlobalMethod buryPointWithPageName:KEY_VerifyQuestion featureName:KEY_Loan_Count action:KEY_GET_FOCUS type:KEY_select];
            [GlobalMethod hitPointWithPageName:KEY_VerifyQuestion action:KEY_Loan_Count_Focus extInfo:nil];
            NSMutableArray * array = [NSMutableArray new];
            for (int i = 0; i <= 10; i ++) {
                ModelBtn * model = [ModelBtn new];
                model.title = [NSString stringWithFormat:@"%d",i];
                model.content = [NSString stringWithFormat:@"%d",[model.title intValue]+1];
                [array addObject:model];
            }
            UIWindow * window = [[[UIApplication sharedApplication] delegate] window];
            [weakSelf.pickerView resetViewWithAry:array withTag:5];
            [window addSubview:weakSelf.pickerView];
        };
    }
    return  _loanNumberView;
}
- (WXPAuthPickerView *)pickerView
{
    if (_pickerView == nil) {
        _pickerView = [WXPAuthPickerView  new];
        WEAKSELF
        _pickerView.blockDidSelectRow = ^(ModelBtn *model, NSInteger tag) {
            if(tag == 1){
                [GlobalMethod buryPointWithPageName:KEY_VerifyQuestion featureName:KEY_Loan_Repayment action:KEY_LOST_FOCUS type:KEY_select];
                if(model != nil){
                    weakSelf.outstandingView.tfContent.text = model.title;
                    weakSelf.outstanding = model.content;
                }
            }else if(tag == 2){
                [GlobalMethod buryPointWithPageName:KEY_VerifyQuestion featureName:KEY_Overdue action:KEY_LOST_FOCUS type:KEY_select];
                if(model != nil){
                    weakSelf.overdueView.tfContent.text = model.title;
                    weakSelf.overdue = model.content;
                }
            }else if(tag == 3){
                [GlobalMethod buryPointWithPageName:KEY_VerifyQuestion featureName:KEY_Overdue_Total action:KEY_LOST_FOCUS type:KEY_select];
                if(model != nil){
                    weakSelf.totalOverdraftView.tfContent.text = model.title;
                    weakSelf.totalOverdraft = model.content;
                }
            }else if(tag == 4){
                [GlobalMethod buryPointWithPageName:KEY_VerifyQuestion featureName:KEY_Overdue_Days action:KEY_LOST_FOCUS type:KEY_select];
                if(model != nil){
                    weakSelf.overdueDaysView.tfContent.text = model.title;
                    weakSelf.overdueDays = model.content;
                }
            }else if(tag == 5){
                [GlobalMethod buryPointWithPageName:KEY_VerifyQuestion featureName:KEY_Loan_Count action:KEY_LOST_FOCUS type:KEY_select];
                if(model != nil){
                    weakSelf.loanNumberView.tfContent.text = model.title;
                    weakSelf.loanNumber = model.content;
                }
            }
            [weakSelf resetEntregarBtn];
        };
    }
    return  _pickerView;
}

#pragma mark - 初始化
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        self.width = SCREEN_WIDTH;
        [self configUI];
    }
    return self;
}

- (void)configUI{
    self.viewContent = [UIView initWithViews:@[
        self.outstandingView,
        self.overdueView,
        self.totalOverdraftView,
        self.overdueDaysView,
        self.loanNumberView,
        [GlobalMethod getViewWithHeight:Ratio(20)],
    ] width:SCREEN_WIDTH-2*LEFT_MARDIN];
    self.viewContent.backgroundColor = COLOR_WHITE;
    [GlobalMethod setRoundView:self.viewContent color:[UIColor clearColor] numRound:16 width:0];
    self.viewContent.centerXTop = XY(self.width/2, 0);
    [self addSubview:self.viewContent];
    self.height = self.viewContent.bottom+Ratio(20);
}

// 提交按钮 - 状态更新
- (void)resetEntregarBtn{
    BOOL clickable = false;
    if(isStr(self.outstandingView.tfContent.text) &&
       isStr(self.overdueView.tfContent.text) &&
       isStr(self.totalOverdraftView.tfContent.text) &&
       isStr(self.overdueDaysView.tfContent.text) &&
       isStr(self.loanNumberView.tfContent.text)){
        clickable = true;
    }else{
        clickable = false;
    }
    if(self.blockResetAuthBtn){
        self.blockResetAuthBtn(clickable);
    }
}


@end
